package com.example.rental.service.impl;

import com.example.rental.entity.Admin;
import com.example.rental.entity.User;
import com.example.rental.entity.condition.UserCondition;
import com.example.rental.mapper.UserMapper;
import com.example.rental.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Transactional(readOnly = true)
    @Override
    public PageInfo<User> searchUsers(UserCondition userCondition) {
        PageHelper.startPage(userCondition.getCurrentPage(),userCondition.getDisplayCount());
        List<User> users = userMapper.getUsers(userCondition);
        return new PageInfo<User>(users);
    }

    @Override
    public Boolean deleteUserByUserid(String userid) {
        return userMapper.deleteUserByUserid(userid);
    }

    @Override
    public void AddUser(User user) {userMapper.addUser(user);}

    @Override
    public void EditUser(User user) {userMapper.updateUser(user);}
    @Override
    public List<Integer> searchUserByUsername(String username) { return userMapper.searchUserByUsername(username); }
    @Override
    public User userLogin(String phone, String password) {

        return userMapper.selectByPhoneAndPwd(phone, password);
    }

    @Override
    public Integer newUser(String rphone, String rpassword) {
        return userMapper.newUser(rphone,rpassword);
    }

    @Override
    public User findByPhone(String phone) {
        return userMapper.findByPhone(phone);
    }

}
